package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import com.sun.activation.registries.MailcapFile;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

/**
 * @author ssm
 * @version v1.0
 * @ClassName CommonController
 * @Date: 2025/6/8 16:22
 * @Description: 通用接口
 */
@RestController
@RequestMapping("/admin/common")
@Slf4j
public class CommonController {

    @Autowired
    private AliOssUtil aliOssUtil;

    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) {
        log.info("文件上传");
        try {

            String originalFilename = file.getOriginalFilename();
            String lastFile = originalFilename.substring(originalFilename.lastIndexOf("."));
            UUID uuid = UUID.randomUUID();
            String fileName = uuid + lastFile;
            log.info("文件名" + fileName);
            String upload = aliOssUtil.upload(file.getBytes(), fileName);
            return Result.success(upload);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
